package com.hbpu.encap.collection;

import java.util.ArrayList;
import java.util.Iterator;

public class Homework02 {
    public static void main(String[] args) {
        Car car = new Car("宝马", 400000);
        Car car2 = new Car("宾利", 5000000);
        ArrayList<Car> cars = new ArrayList<>();
        cars.add(car);
        cars.add(car2);
        for (Car car1 : cars) {
            System.out.println(car1);
        }
        cars.remove(1);
        for (Car car1 : cars) {
            System.out.println(car1);
        }
        System.out.println(cars.contains(car2));
        System.out.println(cars.isEmpty());

        Iterator<Car> iterator = cars.iterator();
        while (iterator.hasNext()) {
            Car next = iterator.next();
            System.out.println(next);
        }
    }
}

class Car {
    private String name;
    private int price;

    public Car(String name, int price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }


}
